package com.budayi.controller;

import com.alibaba.fastjson.JSON;
import com.budayi.common.cache.RedisCacheChannel;
import com.budayi.common.constants.BasicConstants;
import com.budayi.common.service.UserFeignClientService;
import com.budayi.common.utils.ObjectUtils;
import com.budayi.entity.Menu;
import com.budayi.entity.SysUser;
import com.budayi.service.SysUserService;
import com.budayi.vo.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author LIBOFEI
 * @ClassName TestController
 * @description
 * @date 2021/4/19 15:08
 * @Version 1.0
 **/
@RestController
public class TestController {

    @Autowired
    private BasicConstants basicConstants;
    @Autowired(required = false)
    private SysUserService sysUserService;
    @Autowired
    private UserFeignClientService userFeignClientService;
    @Autowired
    private RedisCacheChannel redisCacheChannel;

    @RequestMapping("/test")
    public Object test(){
      return basicConstants.getFileUrl() + ";" + basicConstants.getMqSpace() + ";";
    }

    @RequestMapping("/test/1")
    public Object test1(){
        return sysUserService.queryObjectByPrimaryKey(7L);
    }

    @RequestMapping("/test/2")
    public Object test2(PageInfo pageInfo, SysUser user){
        return sysUserService.queryPageInfoObjectListByCondition(pageInfo,user);
    }

    @RequestMapping("/test/3")
    public Object test3(String username){
        return userFeignClientService.testSystemFeignClientService(username);
    }


    @RequestMapping("/test/4")
    public Object test4(String key ,String username){
        redisCacheChannel.set(key,username);
        return "success";
    }


    @RequestMapping("/test/5")
    public Object test5(String key){

        return redisCacheChannel.get(key);
    }



    @RequestMapping("/test/6")
    public Object test6(String key ,String username){
        Menu menu = new Menu();
        menu.setId(1L);
        menu.setName("12121");
        menu.setParentId(2L);
        menu.setCreateTime(new Date());

        redisCacheChannel.setRegion(key,username,JSON.toJSONString(menu));
        return "success";
    }

    @RequestMapping("/test/7")
    public Object test7(String key ,String username){
       Object object = redisCacheChannel.getRegion(key,username);
        return JSON.parseObject(object.toString(),Menu.class);
    }



    @RequestMapping("/test/8")
    public Object test8(String key){
        Object object = redisCacheChannel.getRegion(key);
        return object;
    }
}
